package com.sekla.comfunc;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "c.TestInterrupt")
public class TestInterrupt {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            try {
                while(true){
                    boolean flag = Thread.currentThread().isInterrupted();
                    if(flag){
                        log.debug("被打断");
                        break;
                    }

                }
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        t.start();
        Thread.sleep(1000);
        // 打断阻塞
        t.interrupt();
        System.out.println(t.isInterrupted());
        // 对于阻塞打断后 flag会被设置为假，会抛出异常
        // 打断正常运行的线程，不会清空打断状态
    }
}
